home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 040 (1987-11-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 040 (1987-11-15)(Ossowski, Stefan)(DE)(PD).adf / SimCPM / simcpm1.asm < prev    next >
Assembly Source File  |  1989-01-18  |  49KB  |  1,613 lines

  1. vermaj     equ    $01    ;Major version number
  2. vermin     equ    $00    ;Minor version number
  3. revyear     equ    $87    ;Year last assembled
  4. revmonth equ    $09    ;Month last assembled
  5. revday     equ    $15    ;Day last assembled
  6. *************************************************************************
  7. *                                    *
  8. *                                    *
  9. *    8080 Simulator for MC68000                    *
  10. *                                    *
  11. *    With CP/M 2.2 call support, and optional tracing        *
  12. *                                    *
  13. *                                    *
  14. *    Converted to AmigaDOS September 1987 by Charlie Gibbs        *
  15. *    (after painstakingly typing it all in from Dr. Dobbs        *
  16. *    Journal, January through March 1986).  Improvements        *
  17. *    described by Jim Cathey    in his letter in the June 1986        *
  18. *    DDJ have been included.     Repetitive code is generated        *
  19. *    by macros whenever it would save my fingers.            *
  20. *                                    *
  21. *                                    *
  22. *    Version    1.2 1/21/85 JEC                        *
  23. *        Fixed Extent bug in OPEN logic.                *
  24. *        Sped up    code, sample MAC from 2:13 to 1:40        *
  25. *        Now runs at a 1.4 MHz equivalent based on MAC sample.    *
  26. *                                    *
  27. *    Version    1.1 8/29/84 JEC                        *
  28. *        Fixed BIOS call    #6 bug.                    *
  29. *                                    *
  30. *    Version    1.0 05/25/84 by    Jim Cathey                *
  31. *                                    *
  32. *    This program has been written for speed    whenever possible,    *
  33. *    as such    tends to be large because of the separate subroutine    *
  34. *    for each and every opcode of the target    processor.        *
  35. *                                    *
  36. *    On an 8MHz 68000 (Compupro) system the simulation speed    is    *
  37. *    a little better    than a 1MHz Z-80 when running MAC.  The    time    *
  38. *    for a sample assembly was 2:13 for the simulation vs. 0:35    *
  39. *    on a 4MHz Z-80,    both systems used identical hard disk systems.    *
  40. *                                    *
  41. *    It is not a complete simulation, as some flag handling        *
  42. *    isn't quite right, but it is enough to run the program          *
  43. *    I wrote    for it (DDT, LU, MAC, and Morrow's FORMATW).            *
  44. *                                    *
  45. *************************************************************************
  46.     code
  47.     page
  48. *************************************************************************
  49. *                                    *
  50. *    This file contains the startup routines, the simulator core,    *
  51. *    tracing    code, and the CP/M 2.2 simulation.            *
  52. *                                    *
  53. *************************************************************************
  54.  
  55.     xref    optabl,flags,mloop,traceit,tracesad,traceead,traceflg
  56.     xdef    illegl,service,dump
  57.  
  58. h19    equ    1        ;Non-zero for H19 emulation
  59.  
  60. *
  61. * ASCII    character values
  62. *
  63. bel    equ    $07        ;Bell (or beep or whatever)
  64. bs    equ    $08        ;Backspace
  65. ht    equ    $09        ;Horizontal tab
  66. lf    equ    $0A        ;Line feed
  67. ff    equ    $0C        ;Form feed
  68. cr    equ    $0D        ;Carriage return
  69. so    equ    $0E        ;Shift out
  70. si    equ    $0F        ;Shift in
  71. esc    equ    $1B        ;Escape
  72.  
  73. *
  74. * Register definitions for the simulation
  75. *  Note, only leaves D0-D1/A0 free for use by entire
  76. *  program without saving registers for temporary use.
  77. *
  78. return     equr    A6        ;JMP (return) is fast return to    MLOOP.
  79. pseudopc equr    A5        ;8080's PC is register A5.
  80. opptr     equr    A4        ;Pointer to opcode dispatch table
  81. pseudosp equr    A3        ;8080's SP is register A3.
  82. flagptr     equr    A2        ;Pointer to 8080's flag lookup table is A2.
  83. targbase equr    A1        ;Pointer to 8080's address space is A1.
  84. regs     equr    A1        ;Base pointer to 8080's registers is A1.
  85. regcon0e equr    D7        ;Register-based    constant #$E (for speed)
  86. regcon01 equr    D6        ;Register-based    constant #$1
  87. regcon0f equr    D5        ;Register-based    constant #$F
  88. regconff equr    D4        ;Register-based    constant #$FF
  89. regf     equr    D3        ;8080's flags
  90. rega     equr    D2        ;8080's accumulator
  91. *
  92. * Target processor's data registers (offsets into storage area)
  93. *
  94. regop3    equ    -9        ;Operand 3 for DAA storage
  95. regb    equ    -8        ;Offsets from register base pointer for
  96. regc    equ    -7        ; 8080's pseudo-registers.
  97. regd    equ    -6        ; A and    F are in 68000's data registers.
  98. rege    equ    -5        ; Pseudo-PC is kept in an address register.
  99. regh    equ    -4
  100. regl    equ    -3
  101. regop1    equ    -2        ;Operand 1 for DAA storage
  102. regop2    equ    -1        ;   "    2  "   "     "
  103.     page
  104. *--------------------------------
  105. *
  106. * Some commonly    used macros
  107. *
  108. *--------------------------------
  109.  
  110. sys    MACRO            ;Call a system routine.
  111.     jsr    _LVO\1(a6)
  112.     ENDM
  113.  
  114. *----------------------
  115. * Equates
  116. *----------------------
  117.  
  118. Absbase      equ 4
  119. MODE_OLDFILE equ 1005
  120. MODE_NEWFILE equ 1006
  121.  
  122. *----------------------
  123. * External references
  124. *----------------------
  125.  
  126.     XREF    _LVOOpenLibrary
  127.     XREF    _LVOCloseLibrary
  128.     XREF    _LVOClose
  129.     XREF    _LVODeleteFile
  130.     XREF    _LVOInput
  131.     XREF    _LVOIoErr
  132.     XREF    _LVOOpen
  133.     XREF    _LVOOutput
  134.     XREF    _LVORead
  135.     XREF    _LVORename
  136.     XREF    _LVOSeek
  137.     XREF    _LVOWaitForChar
  138.     XREF    _LVOWrite
  139.     page
  140. *************************************************************************
  141. *                                    *
  142. *    Initialization                            *
  143. *                                    *
  144. *************************************************************************
  145.  
  146. start:    move.l    sp,savesp    ;Save the stack    pointer.
  147.     move.b    #1,testdol    ;"pstring" should test for leading $.
  148.     clr.w    esclen        ;No partial escape sequence is saved.
  149.     clr.b    insflag        ;We're not in insert mode.
  150.     clr.b    btrcflg        ;Turn off BIOS/BDOS call tracing.
  151.     clr.b    quitflg        ;Clear the quit flag.
  152.     clr.b    bufflag        ;Disable output buffering.
  153.     clr.b    listopn        ;The list device is closed.
  154.     move.l    #strbuf,strptr    ;Initialize output buffer pointer.
  155.  
  156.     lea    handles,a1
  157.     moveq    #(handlen-handles)/4-1,d1
  158. clrhand    clr.l    (a1)+        ;Clear file handles.
  159.     dbra    d1,clrhand
  160.     clr.l    rawhand        ;Clear RAW: handle too.
  161.  
  162. *
  163. * Copy the command line to "cmdline", stripping out leading switches if any.
  164. *
  165.     lea    cmdline,a1
  166.     subq    #1,d0
  167. * Skip over leading blanks, if any.
  168. leadblk    cmpi.b    #' ',(a0)+    ;Leading blank?
  169.     bne.s    bufparm        ;No.
  170.     dbra    d0,leadblk    ;Skip over leading blank.
  171. *  If the first parameter is "-b", skip over it but activate output buffering.
  172. bufparm    subq.l    #1,a0        ;Back onto the first non-blank.
  173.     cmpi.b    #'-',(a0)    ;Possible buffer switch?
  174.     bne.s    savecmd        ;No - start saving the command line.
  175.     cmpi.b    #'B',1(a0)    ;Activate output buffering?
  176.     beq.s    setbuff        ;Yes.
  177.     cmpi.b    #'b',1(a0)
  178.     bne.s    skipsw        ;No.
  179. setbuff    move.b    #1,bufflag    ;Set buffered-output flag.
  180. skipsw    cmpi.b    #' ',(a0)+    ;Skip over the switch.
  181.     beq.s    skipswx        ; and look for start of command line.
  182.     dbra    d0,skipsw
  183.     addq.l    #1,a1        ;Adjust A1.
  184.     bra.s    gotcmd        ;There is no command line left.
  185. skipswx    subq.l    #1,a0        ;Back onto the first blank.
  186.     bra.s    leadblk        ;Look for the next non-blank.
  187. * Save the command line (except for leading switches).
  188. savecmd    move.b    (a0)+,(a1)+    ;Save the command line, if any.
  189.     dbra    d0,savecmd
  190. gotcmd    move.b    #0,-1(a1)    ;Replace the newline with a null.
  191.     move.b    cmdline,cmdflag    ;Save command-line flag.
  192.  
  193. *
  194. * Open libraries and set up a RAW: window.
  195. *
  196.     move.b    #1,quitflg    ;Quit immediately if failure below.
  197.     move.l    Absbase,a6    ;Find library
  198.     lea    dosname,a1    ;'dos.library'
  199.     moveq    #0,d0        ;Any version
  200.     sys    OpenLibrary    ;Open dos.library.
  201.     move.l    d0,a6        ;Point to doslib for next operation.
  202.     move.l    d0,dosbase    ;Save it for future reference.
  203.     sys    Input        ;Get file handle for keyboard.
  204.     move.l    d0,stdin    ;Save it here.
  205.     beq    quitprg        ;Couldn't get keyboard handle.
  206.     sys    Output        ;Get file handle for screen.
  207.     move.l    d0,stdout    ;Save it here.
  208.     beq    quitprg        ;Couldn't get screen handle.
  209.     move.l    #rawspec,d1
  210.     move.l    #MODE_NEWFILE,d2
  211.     sys    Open        ;Open a RAW: window.
  212.     move.l    d0,rawhand    ;Save the file handle here.
  213.     bne.s    opened        ;We succeeded.
  214.     move.l    #rawerr,d1
  215.     bsr    pstring        ;Display error message...
  216.     sys    IoErr
  217.     move.l    d0,d1
  218.     bsr    plong        ; and error code.
  219.     bsr    pcrlf
  220.     bra    quitprg
  221. opened    move.b    cmdflag,quitflg    ;If we have a command, execute it and quit.
  222.     move.l    #setwin,d1
  223.     bsr    pstring        ;Set the window to 24 by 80.
  224.  
  225. *
  226. * Come back here to load another program.
  227. *
  228. nextprg    lea    target,targbase    ;Start of target memory
  229.     clr.b    insflag        ;Reset insert mode.
  230.     move.l    #simsg,d1
  231.     bsr    pstring        ;In case last program sent SHIFT OUT
  232.     clr.b    dumpcnt        ;Reset dump pause counter.
  233.     bsr    entrads        ;Enter trace delimiting    addresses.
  234.     bsr    lodfdos        ;Load up the fake FDOS in target memory.
  235.     bsr    lodregs        ;Load the remaining simulation registers.
  236.     bsr    loadcom        ;Load the .COM program.
  237.  
  238.     jmp    mloop        ;Execute simulation.
  239.     page
  240. *************************************************************************
  241. *                                    *
  242. *    Illegal    instructions and dumping                *
  243. *                                    *
  244. *************************************************************************
  245.  
  246. illegl    move.l    #illgmsg,d1    ;Illegal opcode, say what & where,
  247.     bsr    pstring
  248.     lea    -1(pseudopc),a0
  249.     move.b    (a0),d1
  250.     suba.l    targbase,a0
  251.     bsr    pbyte
  252.     move.l    #ilgmsg2,d1
  253.     bsr    pstring
  254.     move.l    a0,d1
  255.     bsr    pword
  256.     move.l    #ilgmsg3,d1
  257.     bsr    pstring
  258.     move.l    #dumpmsg,d1
  259.     bsr    pstring
  260.     clr.b    dumpcnt
  261.     bsr    dump        ; and spill guts.
  262.     bra    quitprg        ;Quit simulation.
  263.  
  264. dump    movem.l    d0-d2,-(sp)
  265.     move.l    #dmpmsg2,d1    ;Dump all registers,
  266.     bsr    pstring        ; used for illegals and    tracing.
  267.     lea    workbuf,a0
  268.     move.b    rega,d1        ;Accumulator
  269.     bsr    ubyte
  270.     move.b    regf,d1        ;Flags
  271.     bsr    ubyte
  272.     move.b    #' ',(a0)+
  273.     move.w    regb(regs),d1    ;BC
  274.     bsr    uword
  275.     move.b    #' ',(a0)+
  276.     move.w    regd(regs),d1    ;DE
  277.     bsr    uword
  278.     move.b    #' ',(a0)+
  279.     move.w    regh(regs),d1    ;HL
  280.     bsr    uword
  281.     move.b    #' ',(a0)+
  282.     move.l    pseudosp,d1    ;SP
  283.     sub.l    targbase,d1
  284.     bsr    uword
  285.     move.b    #' ',(a0)+
  286.     move.l    a1,-(sp)
  287.     move.l    pseudosp,a1
  288.     swap    d2
  289.     move.w    #3,d2
  290. tosloop    move.b    1(a1),d1    ;Display the top 4 stack entries.
  291.     ror.w    #8,d1
  292.     move.b    0(a1),d1
  293.     bsr    uword
  294.     move.b    #' ',(a0)+
  295.     addq.l    #2,a1
  296.     dbra    d2,tosloop
  297.     move.l    (sp)+,a1
  298.     swap    d2
  299.     move.l    pseudopc,d1    ;PC
  300.     sub.l    targbase,d1
  301.     bsr    uword
  302.     move.b    #' ',(a0)+
  303.     move.b    #' ',(a0)+
  304.     move.b    (pseudopc),d1    ;Current opcode byte
  305.     bsr    ubyte
  306.     move.b    #' ',(a0)+
  307.     move.b    #' ',(a0)+
  308.     move.b    #'$',(a0)+
  309.     move.l    #workbuf,d1
  310.     bsr    pstring        ;Displaying as a single string is much faster.
  311.     moveq    #0,d0
  312.     move.b    (pseudopc),d0    ;Opcode
  313.     mulu    #9,d0        ;Offset into opcode table
  314.     lea    mnops,a0
  315.     move.l    a0,d1
  316.     add.l    d0,d1        ;D1 -> opcode name
  317.     move.l    d1,-(sp)
  318.     addq.l    #1,d1
  319.     bsr    pstring        ;Display opcode name.
  320.     move.l    (sp)+,a0
  321.     cmpi.b    #' ',(a0)
  322.     beq.s    nooprnd        ;There are no operands.
  323.     cmpi.b    #'C',(a0)
  324.     bne.s    notcons
  325.     move.b    1(pseudopc),d1    ;Display single-byte operand.
  326.     bsr    pbyte
  327.     bra.s    nooprnd
  328. notcons    cmpi.b    #'A',(a0)
  329.     bne.s    nooprnd
  330.     move.b    2(pseudopc),d1    ;Display two-byte operand.
  331.     bsr    pbyte
  332.     move.b    1(pseudopc),d1
  333.     bsr    pbyte
  334. nooprnd    bsr    pcrlf
  335.     addq.b    #1,dumpcnt    ;Count the number of times dumped.
  336.     cmpi.b    #8,dumpcnt    ;Is the screen full of dumps?
  337.     bmi.s    dumpx        ;No - exit.
  338.     move.l    #dmpmsg3,d1
  339.     bsr    pstring        ;Ask for operator action.
  340.     bsr    dmpstr        ;Make sure the prompt gets out!
  341.     movem.l    d3/a0-a1/a6,-(sp)
  342.     move.l    rawhand,d1    ;Console input
  343.     move.l    #dumpcnt,d2
  344.     move.l    dosbase,a6
  345.     moveq    #1,d3
  346.     sys    Read        ;Get the operator's reply.
  347.     movem.l    (sp)+,d3/a0-a1/a6
  348.     bsr    pcrlf
  349.     cmpi.b    #'Q',dumpcnt    ;Does he want to quit?
  350.     beq    quitprg        ;Yes.
  351.     cmpi.b    #'q',dumpcnt
  352.     beq    quitprg
  353.     cmpi.b    #'G',dumpcnt    ;Go on with tracing disabled?
  354.     beq.s    dumpnt        ;Yes.
  355.     cmpi.b    #'g',dumpcnt
  356.     bne.s    dmpcont
  357. dumpnt    clr.b    traceflg    ;Disable tracing and continue.
  358. dmpcont    clr.b    dumpcnt        ;Reset the counter.
  359. dumpx    movem.l    (sp)+,d0-d2
  360.     rts
  361.     page
  362. *************************************************************************
  363. *                                    *
  364. *    Initialization subroutines                    *
  365. *                                    *
  366. *************************************************************************
  367.  
  368. *
  369. * Load up the fake FDOS.
  370. *
  371. lodfdos    move.l    a6,-(sp)
  372.     lea    fdos,a6
  373.     move.l    targbase,pseudosp
  374.     adda.l    #$10000,pseudosp
  375.     lea    -256(pseudosp),a0
  376.     move.w    #fdoslen,d0
  377. lodloop    move.b    (a6)+,(a0)+
  378.     dbra    d0,lodloop
  379.     lea    -256(pseudosp),a0
  380.     move.l    a0,d0
  381.     sub.l    targbase,d0
  382.     move.b    #$C3,0(targbase)    ;Build BIOS and    BDOS jumps.
  383.     move.b    #$C3,5(targbase)
  384.     move.b    d0,6(targbase)
  385.     rol.w    #8,d0
  386.     move.b    d0,7(targbase)
  387.     rol.w    #8,d0
  388.     addq.w    #3,d0
  389.     move.b    d0,1(targbase)
  390.     rol.w    #8,d0
  391.     move.b    d0,2(targbase)
  392.     clr.w    -(pseudosp)    ;Set up    a return stack to exit simulation.
  393.     move.l    (sp)+,a6
  394.     rts
  395.  
  396. *
  397. * Set up working registers.
  398. *
  399. lodregs    lea    optabl,opptr    ;Point base reg. to opcode dispatch table.
  400.     lea    mloop,return
  401.     lea    flags,flagptr
  402.     move.l    targbase,pseudopc
  403.     adda.l    #$100,pseudopc    ;Start execution at 0100H in target space.
  404.     moveq    #$E,regcon0e    ;Set up    quick constants.
  405.     moveq    #$1,regcon01
  406.     moveq    #$F,regcon0f
  407.     move.l    #$FF,regconff
  408.     moveq    #0,rega
  409.     moveq    #0,regf
  410.     rts
  411.     page
  412. *
  413. * Get start and end addresses for tracing.
  414. *
  415. entrads    tst.b    traceit        ;Is tracing required?
  416.     beq    entradx        ;No.
  417.     move.l    #tracemsg,d1    ;Enter trace address if    necessary.
  418.     bsr    pstring
  419.     lea    workbuf,a0
  420.     move.b    #workbufn-workbuf-2,(a0)
  421.     bsr    getline        ;Get the string.
  422.     moveq    #0,d0
  423.     move.b    1(a0),d0    ;Number of bytes read
  424.     addq.l    #2,a0        ;Skip over length information.
  425.     clr.b    0(a0,d0)    ;Insert string terminator.
  426.     bsr    atol        ;Get trace start address.
  427.     and.l    #$FFFF,d1
  428.     add.l    targbase,d1
  429.     move.l    d1,tracesad
  430. * Now get the ending address.
  431.     move.l    #tracemg2,d1
  432.     bsr    pstring
  433.     lea    workbuf,a0
  434.     move.b    #workbufn-workbuf-2,(a0)
  435.     bsr    getline
  436.     moveq    #0,d0
  437.     move.b    1(a0),d0
  438.     addq.l    #2,a0
  439.     clr.b    0(a0,d0)
  440.     bsr    atol
  441.     and.l    #$FFFF,d1
  442.     add.l    targbase,d1
  443.     move.l    d1,traceead
  444.     bsr    pcrlf
  445. * Find out whether BIOS/BDOS calls are to be traced.
  446.     move.l    #btrcmsg,d1
  447.     bsr    pstring
  448.     lea    workbuf,a0
  449.     move.b    #10,(a0)
  450.     bsr    getline
  451.     move.b    #1,btrcflg
  452.     cmpi.b    #'Y',workbuf+2
  453.     beq.s    entradx
  454.     cmpi.b    #'y',workbuf+2
  455.     beq.s    entradx
  456.     clr.b    btrcflg
  457. entradx    clr.b    traceflg    ;Start with tracing turned off.
  458.     rts
  459. *
  460. * Open the file to be loaded, and load it into
  461. *  target space    if successful.
  462. *
  463. loadcom    movem.l    d1-d3/a1-a2/a6,-(sp)    ;Save registers.
  464.     lea    cmdline,a0
  465.     tst.b    cmdflag        ;Do we have a command already?
  466.     bne.s    scancmd        ;Yes - process it.
  467. prompt    move.l    #aprompt,d1
  468.     bsr    pstring        ;Display the command prompt.
  469.     lea    cmdline,a0
  470.     move.b    #cmdlinen-cmdline-2,(a0)
  471.     bsr    getline        ;Get a command line.
  472.     moveq    #0,d0
  473.     move.b    1(a0),d0    ;Length of command line
  474.     beq.s    prompt        ;Zero - try again.
  475.     addq.l    #2,a0        ;Skip over length information.
  476.     clr.b    0(a0,d0)    ;Insert    command    line terminator.
  477.     cmpi.b    #3,(a0)        ;Control-C?
  478.     bne.s    scancmd        ;No.
  479.     move.b    #1,quitflg    ;Set quit flag.
  480.     bra    quitprg        ;Exit the simulator.
  481. scancmd    lea    comname,a2
  482.     moveq    #comnamen-comname-6,d1 ;Adjust length for DBcc.
  483. loadnam    bsr    ucase        ;Convert file name to upper case.
  484.     move.b    d0,(a2)+
  485.     cmpi.b    #' ',(a0)       ;End of name?
  486.     beq    gotname        ;Yes.
  487.     tst.b    (a0)        ;End of    command    string?
  488.     dbeq    d1,loadnam    ;No - keep on going.
  489. gotname    move.l    a0,comend    ;Save position in command line.
  490.     move.b    #'.',(a2)+      ;Mash file name to .COM.
  491.     move.b    #'C',(a2)+
  492.     move.b    #'O',(a2)+
  493.     move.b    #'M',(a2)+
  494.     clr.b    (a2)
  495.     clr.b    cmdline        ;Ask for a new command next time.
  496.     move.l    #comname,d1
  497.     move.l    #MODE_OLDFILE,d2
  498.     move.l    dosbase,a6
  499.     sys    Open        ;Open the file.
  500.     tst.l    d0        ;Did the open fail?
  501.     bne.s    comopen        ;No.
  502.     lea    comname,a0
  503. openerr    cmpi.b    #'.',(a0)+      ;Find end of file name.
  504.     bne.s    openerr
  505.     move.b    #'?',-1(a0)
  506.     move.b    #cr,(a0)+
  507.     move.b    #lf,(a0)+
  508.     move.b    #'$',(a0)
  509.     move.l    #comname,d1
  510.     bsr    pstring        ;Echo "name?"
  511.     bra    prompt        ;Try again.
  512.  
  513. comopen    move.l    d0,-(sp)    ;Save the file handle.
  514.     move.l    d0,d1
  515.     move.l    pseudopc,d2    ;Start loading at $0100    in target.
  516.     move.l    #65536-512,d3    ;Maximum number    of bytes to load
  517.     move.l    dosbase,a6
  518.     sys    Read        ;Load the .COM file.
  519.     move.l    (sp)+,d1
  520.     move.l    dosbase,a6
  521.     sys    Close        ;Close the .COM    file.
  522.  
  523. * The program has now been loaded.
  524.     movem.l    (sp)+,d1-d3/a1-a2/a6    ;Refresh registers.
  525.     movem.l    d1-d3/a1-a2/a6,-(sp)
  526.     lea    $80(targbase),a0    ;Set up target's base page.
  527.     move.l    a0,dmaaddr
  528.  
  529. * Set up FCBs and command line tail.
  530.     lea    $5C(targbase),a0
  531.     lea    $6C(targbase),a2
  532.     clr.b    (a0)+
  533.     clr.b    (a2)+
  534.     moveq    #10,d0
  535. clrfcb    move.b    #' ',(a0)+      ;Clear FCBs.
  536.     move.b    #' ',(a2)+
  537.     dbra    d0,clrfcb
  538.     clr.b    $80(targbase)    ;Clear the command line tail.
  539.  
  540.     move.l    comend,a0    ;Restore position in command line.
  541. fcb1    tst.b    (a0)        ;End of    command    line?
  542.     beq    loaded        ;Yes.
  543.     cmpi.b    #' ',(a0)+      ;Skip over to first file name
  544.     beq.s    fcb1
  545.     subq.l    #1,a0        ;Back onto start of file name.
  546.     move.l    a0,-(sp)    ;Save position on command line.
  547.     lea    $81(targbase),a2;A2 loads the command line tail.
  548. gettail    move.b    (a0)+,(a2)+    ;Copy the command tail.
  549.     bne.s    gettail
  550.     move.l    a2,d0
  551.     lea    $82(targbase),a0;Don't count null terminator!
  552.     sub.l    a0,d0
  553.     move.b    d0,$80(targbase);Length    of command line    tail
  554.     move.l    (sp)+,a0    ;Go back to the    first file name.
  555.  
  556.     lea    $5C(targbase),a2;Address of current FCB
  557. getfcb    move.l    a2,fcbptr    ;Save pointer to current FCB.
  558.     cmpi.b    #':',1(a0)      ;Is a drive specified?
  559.     bne.s    getfcbf        ;No.
  560.     move.b    (a0),(a2)    ;Get drive letter.
  561.     subi.b    #'A'-1,(a2)     ;Convert to drive code.
  562.     addq.l    #2,a0        ;Skip over drive designator.
  563.     tst.b    (a0)        ;End of    command    line?
  564.     beq.s    loaded        ;Yes - we're done.
  565.     cmpi.b    #' ',(a0)       ;End of file name?
  566.     beq.s    getfcbx        ;Yes.
  567. getfcbf    addq.l    #1,a2        ;Start of file name in FCB
  568. getfcbl    move.b    (a0)+,(a2)+    ;Copy file name    to FCB.
  569. getfcbt    tst.b    (a0)        ;End of    command?
  570.     beq.s    loaded        ;Yes.
  571.     cmpi.b    #' ',(a0)       ;End of file name?
  572.     beq.s    getfcbx        ;Yes.
  573.     cmpi.b    #'.',(a0)       ;Start of file name extension?
  574.     bne.s    getfcbl        ;No - continue loading file name.
  575.     move.l    fcbptr,a2    ;Copy original pointer
  576.     adda.l    #9,a2        ;Skip over to extension    field.
  577.     addq.l    #1,a0        ;Skip over the period.
  578.     bra.s    getfcbt
  579. getfcbx    tst.b    (a0)        ;End of    command    line?
  580.     beq.s    loaded        ;Yes.
  581.     cmpi.b    #' ',(a0)+      ;Look for another file name.
  582.     beq.s    getfcbx
  583.     subq.l    #1,a0        ;Back onto start of file name.
  584.     move.l    fcbptr,d0
  585.     lea    $5C(targbase),a2
  586.     cmp.l    d0,a2        ;Was this the first FCB?
  587.     bne.s    loaded        ;No - stop after two FCBs.
  588.     adda.l    #16,a2        ;Skip over to the next FCB.
  589.     bra.s    getfcb        ;Load the next FCB.
  590.  
  591. loaded    movem.l    (sp)+,d1-d3/a1-a2/a6    ;Restore registers.
  592.     rts            ;Exit.
  593.  
  594. *
  595. * Subroutine to    get a character    and convert it to upper    case
  596. *
  597. ucase    move.b    (a0)+,d0
  598.     cmpi.b    #'a',d0
  599.     blt.s    ucasex
  600.     cmpi.b    #'z',d0
  601.     bgt.s    ucasex
  602.     subi.b    #'a'-'A',d0
  603. ucasex    rts
  604.     page
  605. *************************************************************************
  606. *                                    *
  607. *    BDOS / BIOS service routines                    *
  608. *                                    *
  609. *************************************************************************
  610. service    movem.l    a1/a6,-(sp)
  611.     move.b    rega,newrega    ;Save 8080 accumulator (D2)
  612.     move.l    dosbase,a6    ;Get dos.library pointer
  613. * Decode the byte following the HLT instruction (BIOS call type).
  614.     moveq    #0,d0        ;Handle    BIOS/BDOS service request
  615.     move.b    (pseudopc)+,d0    ; of form HLT DB opcode.
  616.     cmp    #(biostabn-biostab)/4,d0
  617.     blt.s    dobios        ;Function number is within range.
  618. badbios    move.b    d0,-(sp)    ;Flag illegal BIOS call
  619.     move.l    #ilgbios,d1    ; and spill guts.
  620.     bsr    pstring
  621.     move.b    (sp)+,d1
  622.     bsr    pbyte
  623.     bsr    pcrlf
  624.     bsr    dump
  625.     bra    quitprg
  626. dobios    move.l    d0,-(sp)    ;Save BIOS function number.
  627.     beq.s    biostrx        ;Zero - it's a BDOS call.
  628.     tst.b    btrcflg        ;Trace BIOS calls?
  629.     beq.s    biostrx        ;No.
  630.     move.l    #biosmsg,d1
  631.     bsr    pstring
  632.     move.l    (sp),d1
  633.     bsr    pbyte
  634.     move.l    #atmsg,d1
  635.     bsr    pstring
  636.     move.b    1(pseudosp),d1    ;Address where called (top stack entry)
  637.     ror.w    #8,d1
  638.     move.b    0(pseudosp),d1
  639.     bsr    pword
  640.     bsr    pcrlf
  641.     move.l    (sp),d0
  642. biostrx    asl    #2,d0        ;Multiply function number by 4.
  643.     addi.l    #biostab,d0    ;Point at address table entry.
  644.     movea.l    d0,a0
  645.     movea.l    (a0),a0        ;Point to appropriate service routine.
  646.     move.l    (sp)+,d0    ;Restore BIOS function number.
  647.     jmp    (a0)        ;Jump to the routine.
  648. * If the BIOS code is zero, it's a BDOS call.
  649. *  Decode register C using a similar routine to the BIOS decoding above.
  650. bdosfn    moveq    #0,d0
  651.     move.b    regc(regs),d0    ;Get BDOS function number.
  652.     cmp    #(bdostabn-bdostab)/4,d0
  653.     blt.s    dobdos        ;Function number is within range.
  654. badbdos    move.b    d0,-(sp)
  655.     move.l    #ilgbdos,d1    ;Illegal or unsupported    BDOS call
  656.     bsr    pstring
  657.     move.b    (sp)+,d1
  658.     bsr    pbyte
  659.     bsr    pcrlf
  660.     bsr    dump
  661.     bra    quitprg
  662. dobdos    move.l    d0,-(sp)    ;Save BDOS function number.
  663.     tst.b    btrcflg        ;Trace BDOS calls?
  664.     beq.s    bdostrx        ;No.
  665.     move.l    #bdosmsg,d1
  666.     bsr    pstring
  667.     move.l    (sp),d1
  668.     bsr    pbyte
  669.     move.l    #atmsg,d1
  670.     bsr    pstring
  671.     move.b    1(pseudosp),d1
  672.     ror.w    #8,d1
  673.     move.b    0(pseudosp),d1
  674.     bsr    pword
  675.     bsr    pcrlf
  676.     move.l    (sp),d0
  677. bdostrx    cmpi.b    #10,d0        ;BDOS function 10 or higher?
  678.     blt.s    bdosjmp        ;No.
  679.     bsr    dmpstr        ;Dump any outstanding console output.
  680.     move.l    (sp),d0        ;Restore BDOS function number.
  681. bdosjmp    asl    #2,d0        ;Multiply function number by 4.
  682.     addi.l    #bdostab,d0    ;Point at address table entry.
  683.     movea.l    d0,a0
  684.     movea.l    (a0),a0        ;Point to appropriate service routine.
  685.     move.l    (sp)+,d0    ;Restore BDOS function number.
  686.     moveq    #0,d1
  687.     move.w    regd(regs),d1    ;Get argument.
  688.     jmp    (a0)        ;Jump to the routine.
  689. * Return here after performing the BDOS    function.
  690. results    movem.l    (sp)+,a1/a6
  691.     moveq    #0,rega
  692.     move.b    newrega,rega    ;Get new accumulator value.
  693. * We have finished processing the BDOS function.
  694.     move.b    rega,d0        ;Set flags.
  695.     and.w    regconff,d0
  696.     move.b    0(flagptr,d0.w),regf
  697.     rts
  698. *
  699. * Individual BDOS service routines
  700. *
  701. bdos00    bra    quitprg        ;Exit program.
  702.  
  703. bdos01    bsr    dmpstr        ;Console input
  704.     move.l    rawhand,d1
  705.     move.l    #newrega,d2
  706.     moveq    #1,d3
  707.     sys    Read
  708.     bra    results
  709.  
  710. bdos02    move.b    rege(regs),d1    ;Console output
  711.     clr.b    testdol        ;Allow dollar signs
  712.     bsr    pchar
  713.     bra    results
  714.  
  715. bdos03    equ    badbdos        ;Reader    input
  716.  
  717. bdos04    equ    badbdos        ;Punch output
  718.  
  719. bdos05    pea    rege(regs)    ;List output byte
  720. bdos05t    tst.b    listopn        ;Is the printer already open?
  721.     bne.s    bdos05w        ;Yes.
  722.     move.l    #prtname,d1
  723.     move.l    #MODE_NEWFILE,d2
  724.     sys    Open        ;Open the printer.
  725.     move.l    d0,prthand    ;Save the file handle.
  726.     bne.s    bdos05o        ;The open was successful.
  727.     move.l    #badprt,d1
  728.     bsr    pstring        ;Indicate an unsuccessful open.
  729.     bsr    dump        ;Spill guts...
  730.     bra    quitprg        ; and exit.
  731. bdos05o    move.b    #1,listopn    ;Indicate that the list device is open.
  732. bdos05w    move.l    prthand,d1
  733.     move.l    (sp)+,d2    ;Character to send to the list device
  734.     moveq    #1,d3        ;Just send one byte.
  735.     sys    Write        ;Send the byte to the list device.
  736.     bra    results
  737.     
  738. bdos06    cmpi.b    #$FF,rege(regs)    ;Direct    console    I/O
  739.     bne.s    bdos02        ;Send the byte.
  740.     bsr    dmpstr        ;Dump any outstanding output.
  741.     move.l    rawhand,d1
  742.     moveq    #1,d2        ;Wait for one microsecond.
  743.     sys    WaitForChar    ;Check whether a character is ready.
  744.     tst.l    d0        ;Is a character    ready?
  745.     bne    bdos01        ;Yes - get it.
  746.     clr.b    newrega        ;Indicate that nothing is ready.
  747.     bra    results
  748.  
  749. bdos07    move.b    3(targbase),newrega    ;Get IOBYTE
  750.     bra    results
  751.  
  752. bdos08    move.b    rege(regs),3(targbase)    ;Set IOBYTE
  753.     bra    results
  754.  
  755. bdos09    add.l    targbase,d1    ;Console output    string
  756.     bsr    pstring
  757.     bra    results
  758.  
  759. bdos10    add.l    targbase,d1    ;Console input line
  760.     movea.l    d1,a0        ;The buffer is here.
  761.     bsr    getline        ;Get a line.
  762.     cmpi.b    #3,2(a0)    ;Was it a control-C?
  763.     bne    results        ;No - continue processing.
  764.     bra    quitprg        ;Terminate the program.
  765.  
  766. bdos11    move.l    rawhand,d1    ;Console status check
  767.     moveq    #1,d2        ;Wait for one microsecond.
  768.     sys    WaitForChar    ;Check whether a character is ready.
  769.     move.b    d0,newrega    ;Result    is compatible with CP/M.
  770.     bra    results
  771.  
  772. bdos12    clr.b    regh(regs)    ;Get system identification
  773.     move.b    #$22,regl(regs)    ;Pretend we're CP/M 2.2.
  774.     bra    results
  775.  
  776. bdos13    equ    results        ;Reset all drives (ignored)
  777.  
  778. bdos14    move.b    rege(regs),4(targbase)    ;Select    drive
  779.     bra    results
  780.  
  781. bdos15    move.l    #MODE_OLDFILE,d2;Open existing file
  782. bdos15o    add.l    targbase,d1
  783.     movea.l    d1,a0        ;The FCB is here.
  784.     move.l    d1,-(sp)
  785.     lea    opnname,a1    ;Build AmigaDOS    file name here.
  786.     move.l    a1,d1        ;We'll need it here.
  787.     bsr    convfn        ;Make a    file name.
  788.     sys    Open        ;Open the file.
  789.     move.l    (sp)+,a1    ;The FCB is here.
  790.     lea    handles,a0
  791.     moveq    #(handlen-handles)/4-1,d1
  792.     clr.b    newrega        ;Assume    the open succeeded.
  793.     tst.l    d0        ;Did it fail?
  794.     bne    bdos15s        ;No.
  795.     move.b    #$FF,newrega    ;Set failure code.
  796.     bra    results
  797. bdos15s    tst.l    (a0)+        ;Find an available handle slot.
  798.     dbeq    d1,bdos15s
  799.     tst    d1        ;Did we    find a slot?
  800.     bmi    bdos15e        ;No - error!
  801.     move.l    d0,-4(a0)    ;Save file handle address.
  802.     moveq    #(handlen-handles)/4-1,d0
  803.     sub.l    d1,d0
  804.     move.b    d0,13(a1)    ;Save handle number in FCB.
  805.     bra    results
  806. bdos15e    move.l    #fullmsg,d1    ;File handle table overflow!
  807.     bsr    pstring        ;Display an error message
  808.     bra    quitprg        ; and forget the whole thing.
  809.  
  810. bdos16    move.b    #$FF,newrega    ;Close file
  811.     bsr    gethand        ;Get the file handle.
  812.     beq    results        ;The file is not open.
  813.     clr.l    0(a1,d0.w)    ;Clear the handle table    entry.
  814.     sys    Close        ;Close the file.
  815.     clr.b    newrega        ;Indicate success.
  816.     bra    results
  817.  
  818. bdos17    equ    badbdos        ;Search    for first file
  819.  
  820. bdos18    equ    badbdos        ;Search    for next file
  821.  
  822. bdos19    add.l    targbase,d1    ;Delete    file
  823.     movea.l    d1,a0        ;The FCB is here.
  824.     lea    opnname,a1    ;Build AmigaDOS    file name here.
  825.     move.l    a1,d1        ;We'll need it here.
  826.     bsr    convfn        ;Make a    file name.
  827.     sys    DeleteFile    ;Delete    the file.
  828.     bra    results
  829.  
  830. bdos20    clr.b    newrega        ;Sequential read
  831.     bsr    gethand
  832.     move.l    dmaaddr,d2
  833.     move.l    #128,d3
  834.     sys    Read
  835.     tst.l    d0        ;Were we successful?
  836.     bgt    results        ;Yes.
  837.     move.b    #$FF,newrega    ;Set failure (EOF) flag.
  838.     bra    results
  839.  
  840. bdos21    clr.b    newrega        ;Sequential write
  841.     bsr    gethand
  842.     move.l    dmaaddr,d2
  843.     move.l    #128,d3
  844.     sys    Write
  845.     tst.l    d0        ;Were we successful?
  846.     bgt    results        ;Yes.
  847.     move.b    #$FF,newrega    ;Set failure flag.
  848.     bra    results
  849.  
  850. bdos22    move.l    #MODE_NEWFILE,d2    ;Make new file
  851.     bra    bdos15o            ;Use BDOS 15 open routine
  852.  
  853. bdos23    add.l    targbase,d1    ;Rename    file
  854.     movea.l    d1,a0
  855.     lea    opnname,a1
  856.     bsr    convfn        ;Convert old file name.
  857.     movea.l    d1,a0
  858.     adda.l    #16,a0
  859.     lea    renname,a1
  860.     bsr    convfn        ;Convert new file name.
  861.     move.l    #opnname,d1
  862.     move.l    #renname,d2
  863.     sys    Rename        ;Rename    the file.
  864.     bra    results
  865.  
  866. bdos24    equ    badbdos        ;Get active drive map
  867.  
  868. bdos25    move.b    4(targbase),newrega    ;Get default drive number
  869.     bra    results
  870.  
  871. bdos26    add.l    targbase,d1    ;Set file buffer address
  872.     move.l    d1,dmaaddr
  873.     bra    results
  874.  
  875. bdos27    equ    badbdos        ;Get allocation    vector
  876.  
  877. bdos28    equ    badbdos        ;Protect drive
  878.  
  879. bdos29    equ    badbdos        ;Get read-only map
  880.  
  881. bdos30    equ    badbdos        ;Set file attributes
  882.  
  883. bdos31    equ    badbdos        ;Get disk parameter block
  884.  
  885. bdos32    equ    badbdos        ;Get or    set user code
  886.  
  887. bdos33    pea    _LVORead(a6)    ;Direct access read
  888.     bra.s    bdos34c        ;Use common read/write routine.
  889.  
  890. bdos34    pea    _LVOWrite(a6)    ;Direct access write
  891. bdos34c    clr.b    newrega        ;Common direct access read/write routine
  892.     bsr    gethand
  893.     move.l    d1,-(sp)    ;Save file handle.
  894.     moveq    #0,d2
  895.     move.b    35(a0),d2    ;Get seek address.
  896.     rol.l    #8,d2
  897.     move.b    34(a0),d2
  898.     rol.l    #8,d2
  899.     move.b    33(a0),d2
  900.     rol.l    #7,d2        ;Convert record number to byte displacement.
  901.     move.b    33(a0),32(a0)    ;Set up current record number in extent.
  902.     andi.b    #$7F,32(a0)
  903.     moveq    #14,d0
  904.     ror.l    d0,d2
  905.     move.b    d2,12(a0)    ;Current extent number
  906.     rol.l    d0,d2
  907.     moveq    #-1,d3
  908.     sys    Seek        ;Seek to desired position.
  909.     move.l    (sp)+,d1    ;Get the file handle again.
  910.     move.l    (sp)+,a0    ;Address of read or write routine
  911.     tst.l    d0        ;Were we successful?
  912.     bmi    bdos34e        ;No.
  913.     move.l    dmaaddr,d2
  914.     move.l    #128,d3
  915.     jsr    (a0)        ;Read or write the desired record.
  916.     tst.l    d0        ;Were we successful?
  917.     bgt    results        ;Yes.
  918. bdos34e    move.b    #6,newrega    ;Set failure (invalid address) flag.
  919.     bra    results
  920.  
  921. bdos35    equ    badbdos        ;Get file end address
  922.  
  923. bdos36    equ    badbdos        ;Get direct address
  924.  
  925. *
  926. * Individual BIOS service routines
  927. *
  928. bios01    bra    quitprg        ;Warm boot
  929.  
  930. bios02    equ    bdos11        ;Console status check
  931.  
  932. bios03    equ    bdos01        ;Console input byte
  933.  
  934. bios04    move.b    regc(regs),d1    ;Console output byte
  935.     clr.b    testdol        ;Allow dollar signs
  936.     bsr    pchar
  937.     bra    results
  938.  
  939. bios05    pea    regc(regs)    ;List output byte
  940.     bra    bdos05t
  941.  
  942. bios06    equ    badbios        ;Punch output byte
  943.  
  944. bios07    equ    badbios        ;Reader input byte
  945.  
  946. bios08    equ    badbios        ;Home disk
  947.  
  948. bios09    equ    badbios        ;Select disk
  949.  
  950. bios10    equ    badbios        ;Set track
  951.  
  952. bios11    equ    badbios        ;Set sector
  953.  
  954. bios12    equ    badbios        ;Set DMA address
  955.  
  956. bios13    equ    badbios        ;Read disk
  957.  
  958. bios14    equ    badbios        ;Write disk
  959.  
  960. bios15    move.b    #$FF,newrega    ;List status
  961.     bra    results
  962.  
  963.  
  964. *
  965. * End of program, one way or another
  966. *
  967. quitprg    move.l    savesp,sp    ;Restore stack pointer.
  968.     bsr    dmpstr        ;Dump any outstanding console output.
  969. * If the list device was used, close it.
  970.     tst.b    listopn        ;Is the printer open?
  971.     beq.s    closprt        ;No.
  972.     move.l    prthand,d1
  973.     sys    Close        ;Close the printer.
  974. closprt    clr.b    listopn        ;Reset the "printer-open" flag.
  975. * If any files were left open by the last program, close them.
  976.     lea    handles,a0
  977.     moveq    #(handlen-handles)/4-1,d0
  978. closall    move.l    (a0)+,d1
  979.     beq.s    closnxt        ;This file isn't open.
  980.     movem.l    a0/d0,-(sp)
  981.     move.l    dosbase,a6
  982.     sys    Close        ;Close this file.
  983.     movem.l    (sp)+,a0/d0
  984. closnxt    dbra    d0,closall
  985. * Check whether we should quit the simulation.
  986.     tst.b    quitflg        ;Exit the simulator?
  987.     bne.s    exitsim        ;Yes.
  988.     tst.b    cmdflag        ;Was .COM file loaded from command line?
  989.     beq    nextprg        ;No - re-display the command prompt.
  990. * Terminate execution of the simulator.
  991. exitsim    move.l    rawhand,d1    ;Is RAW: open?
  992.     beq.s    closlib        ;No.
  993.     move.l    dosbase,a6
  994.     sys    Close        ;Close RAW:
  995. closlib    move.l    Absbase,a6
  996.     move.l    dosbase,a1
  997.     sys    CloseLibrary    ;Close dos.library.
  998.     moveq    #0,d0        ;Return    with no    error.
  999.     rts            ;All done
  1000.     page
  1001. *************************************************************************
  1002. *                                    *
  1003. *    AmigaDOS interface routines                    *
  1004. *                                    *
  1005. *************************************************************************
  1006.  
  1007. *
  1008. * Get a line from the console.  CP/M BDOS 10 conventions are used.
  1009. *  A0 is assumed to point to the start of the buffer.
  1010. *  If the first character encountered is a control-C, this routine
  1011. *  exits, leaving just the control-C in the buffer.
  1012. *
  1013. getline    movem.l    d2-d3/a0-a1/a6,-(sp)
  1014.     bsr    dmpstr        ;Flush the screen buffer first.
  1015.     move.l    dosbase,a6
  1016.     movea.l    a0,a1
  1017.     addq.l    #2,a1        ;The current character loads here.
  1018.     clr.b    1(a0)        ;Clear character count.
  1019. getlinl    move.l    rawhand,d1    ;Read from RAW:
  1020.     move.l    a1,d2        ; into current position
  1021.     moveq    #1,d3        ;  for a length of one byte.
  1022.     movem.l    d1-d3/a0-a1,-(sp)
  1023.     sys    Read        ;Get a character.
  1024.     movem.l    (sp)+,d1-d3/a0-a1
  1025.     cmpi.b    #cr,(a1)    ;Did we get a carriage return?
  1026.     beq.s    getlinc        ;Yes - stop here.
  1027.     cmpi.b    #lf,(a1)    ;Stop on a line feed too.
  1028.     beq.s    getlinc
  1029.     cmpi.b    #bs,(a1)    ;Backspace?
  1030.     bne.s    getlinp        ;No.
  1031.     tst.b    1(a0)        ;Do we have anything yet?
  1032.     beq.s    getlinl        ;No - ignore the backspace.
  1033.     subq.l    #1,a1        ;Back over the previous character.
  1034.     subq.b    #1,1(a0)    ;Decrement character count.
  1035.     movem.l    a0-a1,-(sp)
  1036.     move.l    #bsmsg,d1
  1037.     jsr    pstring        ;Erase the previous character on the screen.
  1038.     movem.l    (sp)+,a0-a1
  1039.     bra.s    getlinl
  1040. getlinp    movem.l    a0-a1,-(sp)
  1041.     sys    Write        ;Echo the current character.
  1042.     movem.l    (sp)+,a0-a1
  1043. getlinn    addq.b    #1,1(a0)    ;Bump character count.
  1044.     move.b    1(a0),d0    ;Number of bytes read so far.
  1045.     cmpi.b    #3,(a1)+    ;Did we get a control-C?
  1046.     bne.s    getlinf        ;No.
  1047.     cmpi.b    #1,d0        ;Is is the first character?
  1048.     beq.s    getlinx        ;Yes - exit now.
  1049. getlinf    cmp.b    (a0),d0        ;Is the buffer full?
  1050.     bne.s    getlinl        ;No - try for another character.
  1051.     bra.s    getlinx
  1052. getlinc    bsr    pcrlf        ;Carriage return or line feed
  1053. getlinx    movem.l    (sp)+,d2-d3/a0-a1/a6
  1054.     rts            ;Exit.
  1055.  
  1056. *
  1057. * Display the message pointed to by D1.
  1058. *  The message must be terminated by a dollar sign.
  1059. *
  1060. pstring    movem.l    d2-d3/a1-a2,-(sp)    ;Save work registers.
  1061.     move.l    d1,a0        ;A0 scans the message.
  1062.     bset    #0,testdol    ;Suppress $ test?
  1063.     beq.s    pstrs        ;Yes (used by BDOS/BIOS character output)
  1064.     cmpi.b    #'$',(a0)    ;Null string?
  1065.     beq    pstrx        ;Yes - do nothing.
  1066. pstrs    move.l    strptr,a1    ;A1 loads the output buffer.
  1067.     move.l    #strbufn,d3
  1068.     sub.l    a1,d3        ;Number of bytes left in buffer
  1069.     ifne    h19
  1070.     moveq    #0,d0
  1071.     move.w    esclen,d0    ;Is a partial escape sequence saved?
  1072.     beq.s    pstrl        ;No.
  1073.     lea    escbuf,a2
  1074.     adda.l    d0,a2        ;Continue loading it here.
  1075.     clr.w    esclen        ;Reset "saved length" counter.
  1076.     cmpi.w    #2,d0        ;Did we just save one byte?
  1077.     blt.s    pstresc        ;Yes - get the remainder.
  1078.     bhi    pstreY2        ;Get the last cursor positioning byte.
  1079.     subq.l    #1,a2        ;Back over dummy byte.
  1080.     bra    pstreY1        ;Get both cursor positioning bytes.
  1081.     endc
  1082. pstrl:    cmpi.b    #lf,(a0)    ;Line feed?
  1083.     bne.s    notlf        ;No.
  1084.     lea    escbuf,a2    ;Translate it to a cursor-down sequence.
  1085.     move.b    #$9B,(a2)+
  1086.     move.b    #'B',(a2)+
  1087.     addq.l    #1,a0
  1088.     bra    pstrsub
  1089. notlf:
  1090.     ifne    h19
  1091. * Optional H19 escape sequence translation
  1092.     cmpi.b    #esc,(a0)    ;Escape character?
  1093.     bne    pstrm        ;No - treat it normally.
  1094.     lea    escbuf,a2    ;Build translated escape sequence here.
  1095.     move.b    #$9B,(a2)+    ;Start with an AmigaDOS escape character.
  1096.     addq.l    #1,a0        ;Check the next character.
  1097.     cmpi.b    #'$',(a0)    ;End of string?
  1098.     bne.s    pstresc        ;No - analyze the sequence.
  1099.     move.w    #1,esclen    ;We've saved one byte for next time.
  1100.     bra    pstrw        ;Write everything up to the ESC character.
  1101. pstresc    move.b    (a0)+,d0
  1102.     cmpi.b    #'[',d0        ;ANSI escape sequence?
  1103.     beq    pstrsub        ;Yes - pass the sequence with $9B header.
  1104.     cmpi.b    #'Y',d0
  1105.     beq.s    pstreY        ;Set cursor position.
  1106.     cmpi.b    #'@',d0
  1107.     beq.s    pstrein        ;Set insert mode.
  1108.     cmpi.b    #'A',d0
  1109.     blt.s    pstreun        ;Unknown code - copy it as is.
  1110.     cmpi.b    #'O',d0
  1111.     beq.s    pstreO        ;Reset insert mode.
  1112.     bhi.s    pstreun        ;Unknown code
  1113.     move.l    a0,-(sp)
  1114.     lea    esctran,a0    ;Translation table with offset
  1115.     move.b    -'A'(a0,d0.w),d2;Get the translated code.
  1116.     move.l    (sp)+,a0
  1117.     btst    #6,d2        ;Does the translated code stand alone?
  1118.     bne.s    pstresb        ;No.
  1119.     subq.l    #1,a2        ;Back over stored CSI character.
  1120. pstresb    move.b    d2,(a2)+    ;Get the translated code.
  1121.     bra.s    pstrsub
  1122. pstrein    move.b    #1,insflag    ;Set insert mode.
  1123.     bra.s    pstrsbx
  1124. pstreO    clr.b    insflag        ;Reset insert mode.
  1125.     bra.s    pstrsbx
  1126. pstreY    cmpi.b    #'Y',d0        ;Set cursor position
  1127.     bne.s    pstreun
  1128.     cmpi.b    #'$',(a0)    ;End of string?
  1129.     bne.s    pstreY1        ;No.
  1130.     move.w    #2,esclen    ;Indicate we need both position bytes.
  1131.     bra    pstrw        ;Finish the sequence next time.
  1132. pstreY1    moveq    #0,d0
  1133.     move.b    (a0)+,d0    ;Get the first position byte.
  1134.     bsr    pstrcvd        ;Convert to decimal in save area.
  1135.     move.b    #';',(a2)+    ;Add the separator character.
  1136.     cmpi.b    #'$',(a0)    ;End of string?
  1137.     bne.s    pstreY2        ;No.
  1138.     sub.l    #escbuf,a2    ;Number of bytes saved
  1139.     move.w    a2,esclen
  1140.     bra    pstrw        ;Get the last byte next time.
  1141. pstreY2    moveq    #0,d0
  1142.     move.b    (a0)+,d0    ;Get the last position byte.
  1143.     bsr    pstrcvd        ;Convert to decimal in save area.
  1144.     move.b    #'H',(a2)+    ;Terminate the sequence.
  1145.     bra.s    pstrsub
  1146. pstreun    move.b    #esc,escbuf    ;Unidentified escape sequence -
  1147.     move.b    d0,(a2)+    ; pass it through as is.
  1148. * The translated escape sequence is now in "escbuf" -
  1149. *  copy it to the output buffer.
  1150. pstrsub    move.l    a2,d0
  1151.     lea    escbuf,a2    ;A2 scans translated escape sequence.
  1152.     sub.l    a2,d0        ;Length of translated escape sequence
  1153.     subq.l    #1,d0
  1154. pstrsbl    move.b    (a2)+,(a1)+    ;Copy substitution to output string.
  1155.     subq.w    #1,d3        ;Count down remaining length.
  1156.     dbra    d0,pstrsbl
  1157. pstrsbx    cmpi.b    #'$',(a0)    ;End of string?
  1158.     beq    pstrw        ;Yes - write it out.
  1159.     tst.w    d3        ;Is the buffer full?
  1160.     bmi    pstrw        ;Yes - write out what we have.
  1161.     cmpi.b    #lf,-1(a0)    ;Line feed?
  1162.     bne    pstrl        ;No.
  1163.     tst.b    bufflag        ;Is console buffering in effect?
  1164.     beq    pstrl        ;No.
  1165.     move.l    a1,strptr
  1166.     bsr    dmpstr        ;Dump the buffer.
  1167.     move.l    strptr,a1
  1168.     bra    pstrl        ;Check for another escape sequence.
  1169. * Subroutine to convert the byte in D0 to a character string at (A2)+
  1170. pstrcvd    subi.b    #' '-1,d0    ;Convert to binary row or column number.
  1171.     divu    #10,d0        ;Convert to tens and units.
  1172.     tst.w    d0        ;Is the number 10 or greater?
  1173.     beq.s    pstrcv1        ;No - just create a one-digit number.
  1174.     addi.b    #'0',d0        ;Convert the tens digit to ASCII.
  1175.     move.b    d0,(a2)+    ;Move it to the result field.
  1176. pstrcv1    swap    d0        ;Get the units digit.
  1177.     addi.b    #'0',d0        ;Convert it to ASCII.
  1178.     move.b    d0,(a2)+
  1179.     rts
  1180.     endc
  1181. * Normal character processing
  1182. pstrm    tst.b    insflag        ;Are we in insert mode?
  1183.     beq.s    pstrmv        ;No.
  1184.     lea    escbuf,a2
  1185.     move.b    #$9B,(a2)+    ;Build an insert-character sequence.
  1186.     move.b    #'@',(a2)+
  1187.     move.b    (a0)+,(a2)+    ;Here's the character to insert.
  1188.     bra.s    pstrsub        ;Use the substitution routine.
  1189. pstrmv    move.b    (a0)+,(a1)+    ;Move one character.
  1190.     tst.b    bufflag        ;Is console buffering in effect?
  1191.     beq.s    pstreos        ;No.
  1192.     cmpi.b    #cr,-1(a0)    ;Carriage return?
  1193.     beq.s    pstrseg        ;Yes - dump the current segment.
  1194.     cmpi.b    #bel,-1(a0)    ;Bell?
  1195.     bne.s    pstreos        ;No - continue buffering.
  1196. pstrseg    move.l    a1,strptr
  1197.     bsr    dmpstr        ;Dump the buffer.
  1198.     move.l    strptr,a1
  1199. pstreos    cmpi.b    #'$',(a0)    ;Test for end of string.
  1200.     dbeq    d3,pstrl    ;Loop until we get there or buffer is full.
  1201. pstrw    move.l    a1,strptr
  1202.     tst    d3        ;Is the buffer full?
  1203.     bmi.s    pstrdmp        ;Yes - dump it regardless.
  1204.     tst.b    bufflag        ;Is console buffering in effect?
  1205.     bne.s    pstrnxt        ;Yes - don't write anything yet.
  1206. pstrdmp    bsr    dmpstr        ;Dump the buffer.
  1207.     move.l    strptr,a1
  1208. pstrnxt    tst    d3        ;Did the output buffer overflow?
  1209.     bmi    pstrs        ;Yes - get another section of the message.
  1210. pstrx    movem.l    (sp)+,d2-d3/a1-a2    ;Restore registers
  1211.     rts
  1212. *
  1213. * Write the contents of "strbuf" to RAW: if possible, or stdout if not.
  1214. *  The number of bytes to be written is calculated from "strptr".
  1215. *
  1216. dmpstr    movem.l    d2-d3/a0-a1/a6,-(sp)
  1217.     move.l    strptr,d3
  1218.     move.l    #strbuf,d2    ;Address of buffer
  1219.     move.l    d2,strptr    ;Reset the buffer pointer.
  1220.     sub.l    d2,d3        ;Length of output string
  1221.     beq.s    dmpstrx        ;Zero - don't write anything.
  1222.     move.l    rawhand,d1    ;Assume we're writing to RAW:
  1223.     bne.s    dmpstrp
  1224.     move.l    stdout,d1    ;We don't have RAW: - use stdout.
  1225. dmpstrp    move.l    dosbase,a6
  1226.     sys    Write        ;Display the line.
  1227. dmpstrx    movem.l    (sp)+,d2-d3/a0-a1/a6
  1228.     rts
  1229.  
  1230. *
  1231. * Convert the file name    in the FCB pointed to by A0
  1232. *  to an AmigaDOS-format file name in the field    pointed    to by A1.
  1233. *  D0 is the only other    register used by this routine.
  1234. *
  1235. convfn    move.l    a1,-(sp)
  1236.     move.l    a0,-(sp)    ;Save start address of FCB.
  1237.     tst.b    (a0)+        ;Skip over drive code for now.
  1238.     moveq    #7,d0        ;Maximum of 8 characters for file name
  1239. convfn1    cmpi.b    #' ',(a0)       ;End of file name?
  1240.     beq.s    convfnz        ;Yes
  1241.     move.b    (a0)+,(a1)+    ;Move one character of file name.
  1242.     dbra    d0,convfn1    ;Try for more.
  1243. convfnz    movea.l    (sp)+,a0    ;Back to start of FCB.
  1244.     adda.l    #9,a0        ;Go to start of    file name extension.
  1245.     cmpi.b    #' ',(a0)       ;Do we have an extension?
  1246.     beq.s    convfnx        ;No.
  1247.     move.b    #'.',(a1)+      ;Insert extension separator.
  1248.     moveq    #2,d0        ;Maximum of 3 characters for extension.
  1249. convfn2    cmpi.b    #' ',(a0)       ;End of extension?
  1250.     beq.s    convfnx        ;Yes.
  1251.     move.b    (a0)+,(a1)+    ;Move one character of extension.
  1252.     dbra    d0,convfn2    ;Try for more.
  1253. convfnx    clr.b    (a1)        ;Terminate file    name string.
  1254.     move.l    (sp)+,a1
  1255.     rts
  1256.  
  1257. *
  1258. * Get the file handle indicated    by the number inserted into the
  1259. *  CP/M    FCB by the open    routine.  It is    copied from the    file handle
  1260. *  table entry (whose address is set up    as 0(A1,D0.W)) to D1.
  1261. *  The Z flag will be set if the handle    is zero    (i.e. file not open).
  1262. *  A0 points to    the FCB.
  1263. *
  1264. gethand    add.l    targbase,d1    ;The FCB is here.
  1265.     movea.l    d1,a0
  1266.     lea    handles,a1
  1267.     moveq    #0,d0
  1268.     move.b    13(a0),d0    ;Get handle number from    FCB.
  1269.     asl.w    #2,d0        ;Convert to table offset.
  1270.     move.l    0(a1,d0.w),d1    ;Get the file handle.
  1271.     rts
  1272.     page
  1273. *************************************************************************
  1274. *                                    *
  1275. *    Miscellaneous service routines                    *
  1276. *    (Inelegant, but    rarely used so they stand as is.)        *
  1277. *                                    *
  1278. *************************************************************************
  1279.  
  1280. *
  1281. * Display the contents of D1 in hex.
  1282. *
  1283. pbyte    move.l    #$20018,d0    ;2 nybbles, 24-bit shift first
  1284.     bra.s    phex
  1285. pword    move.l    #$40010,d0    ;4 nybbles, 16-bit shift first
  1286.     bra.s    phex
  1287. paddr    move.l    #$60008,d0    ;6 nybbles, 8-bit shift    first
  1288.     bra.s    phex
  1289. plong    move.l    #$80000,d0    ;8 nybbles, no shift first
  1290. phex    lea    workbuf,a0
  1291.     move.l    a0,-(sp)
  1292.     bsr    pdigits
  1293.     move.b    #'$',(a0)+
  1294.     move.l    (sp)+,d1
  1295.     bsr    pstring
  1296.     rts
  1297. *
  1298. * Convert the contents of D1 to hex at (A0).
  1299. *  On exit, A0 points to the next available byte.
  1300. *
  1301. ubyte    move.l    #$20018,d0    ;2 nybbles, 24-bit shift first
  1302.     bra.s    pdigits
  1303. uword    move.l    #$40010,d0    ;4 nybbles, 16-bit shift first
  1304.     bra.s    pdigits
  1305. uaddr    move.l    #$60008,d0    ;6 nybbles, 8-bit shift    first
  1306.     bra.s    pdigits
  1307. ulong    move.l    #$80000,d0    ;8 nybbles, no shift first
  1308. pdigits    rol.l    d0,d1        ;Do shift.
  1309.     bra.s    pdigent
  1310. pdiglop    swap    d0        ;Save nybble count.
  1311.     rol.l    #4,d1        ;Print variable    in d1.
  1312.     move.l    d1,-(sp)
  1313.     and    #$F,d1        ;Isolate the current nybble.
  1314.     cmp    #$A,d1
  1315.     blt.s    ntoa2
  1316.     add.b    #'A'-'9'-1,d1    ;Adjust for digits A through F.
  1317. ntoa2    add.b    #'0',d1        ;Convert to ASCII.
  1318.     move.b    d1,(a0)+    ;Add to the result string.
  1319.     move.l    (sp)+,d1
  1320. pdigent    swap    d0        ;Get nybble count.
  1321.     dbra    d0,pdiglop
  1322.     rts
  1323.  
  1324. pchar    move.b    d1,workbuf    ;Print the character in D1.
  1325.     move.b    #'$',workbuf+1
  1326.     move.l    #workbuf,d1
  1327.     bsr    pstring
  1328.     rts
  1329.  
  1330. pspace    move.l    #spacemsg,d1    ;Print a space.
  1331.     bsr    pstring
  1332.     rts
  1333.  
  1334. pcrlf    move.l    #crlfmsg,d1    ;Print a carriage return and line feed.
  1335.     bsr    pstring
  1336.     rts
  1337.  
  1338. *
  1339. * Convert the hex string pointed to by A0 to long in d1.
  1340. *  Stops on the    first invalid hex digit, which is returned in d0.
  1341. *  A0 is left pointing to this first invalid digit.
  1342. *  d2 =    1 if any valid digits were found, 0 otherwise.
  1343. *
  1344. atol    moveq    #0,d1
  1345.     moveq    #0,d2
  1346. atol1    move.b    (a0)+,d0    ;Get the current byte.
  1347.     cmpi.b    #$40,d0
  1348.     blt.s    atol2
  1349.     and    #$5F,d0        ;Mask to upper case.
  1350. atol2    cmpi.b    #'0',d0         ;Check range (0..9,A..F).
  1351.     blt.s    atolend
  1352.     cmpi.b    #'F',d0
  1353.     bhi.s    atolend
  1354.     cmpi.b    #'9',d0
  1355.     ble.s    atol3
  1356.     cmpi.b    #'A'-1,d0
  1357.     bhi.s    atol3
  1358.     bra.s    atolend
  1359. atol3    moveq    #1,d2        ;Valid characters entered, set flag.
  1360.     sub.b    #'0',d0         ;Convert to binary
  1361.     cmp.b    #$9,d0        ;Digit in range    0..9?
  1362.     ble.s    atol4        ;Yes - conversion is complete
  1363.     sub.b    #'A'-'9'-1,d0   ;Adjust digits A..F.
  1364. atol4    ext    d0        ;Convert to long.
  1365.     ext.l    d0
  1366.     asl.l    #4,d1        ;Tack it onto d1.
  1367.     add.l    d0,d1
  1368.     bra.s    atol1        ;Try for another digit.
  1369. atolend    subq.l    #1,a0        ;Back onto the first invalid digit.
  1370.     rts
  1371.     page
  1372. *************************************************************************
  1373. *                                    *
  1374. *    This table contains the mnemonic strings for the 8080        *
  1375. *    opcodes.  These    are used in tracing.  The first    character    *
  1376. *    flags operands.     Blank is nothing, A is    an address (i.e.    *
  1377. *    a 16-bit value), and C is a constant (i.e. an 8-bit value).    *
  1378. *                                    *
  1379. *************************************************************************
  1380.  
  1381.     data    data
  1382.  
  1383. mnops:
  1384.     dc.b    ' NOP$    ALXI B,$  STAX B$  INX B$  '  ;00-03
  1385.     dc.b    ' INR B$   DCR B$  CMVI B,$  RLC$    '  ;04-07
  1386.     dc.b    ' ILLEGAL$ DAD B$   LDAX B$  DCX B$  '  ;08-0B
  1387.     dc.b    ' INR C$   DCR C$  CMVI C,$  RRC$    '  ;0C-0F
  1388.     dc.b    ' ILLEGAL$ALXI D,$  STAX D$  INX D$  '  ;10-13
  1389.     dc.b    ' INR D$   DCR D$  CMVI D,$  RAL$    '  ;14-17
  1390.     dc.b    ' ILLEGAL$ DAD D$   LDAX D$  DCX D$  '  ;18-1B
  1391.     dc.b    ' INR E$   DCR E$  CMVI E,$  RAR$    '  ;1C-1F
  1392.     dc.b    ' ILLEGAL$ALXI H,$ ASHLD $   INX H$  '  ;20-23
  1393.     dc.b    ' INR H$   DCR H$  CMVI H,$  DAA$    '  ;24-27
  1394.     dc.b    ' ILLEGAL$ DAD H$  ALHLD $   DCX H$  '  ;28-2B
  1395.     dc.b    ' INR L$   DCR L$  CMVI L,$  CMA$    '  ;2C-2F
  1396.     dc.b    ' ILLEGAL$ALXI SP,$ASTA $    INX SP$ '  ;30-33
  1397.     dc.b    ' INR M$   DCR M$  CMVI M,$  STC$    '  ;34-37
  1398.     dc.b    ' ILLEGAL$ DAD SP$ ALDA $    DCX SP$ '  ;38-3B
  1399.     dc.b    ' INR A$   DCR A$  CMVI A,$  CMC$    '  ;3C-3F
  1400.     dc.b    ' MOV B,B$ MOV B,C$ MOV B,D$ MOV B,E$'  ;40-43
  1401.     dc.b    ' MOV B,H$ MOV B,L$ MOV B,M$ MOV B,A$'  ;44-47
  1402.     dc.b    ' MOV C,B$ MOV C,C$ MOV C,D$ MOV C,E$'  ;48-4B
  1403.     dc.b    ' MOV C,H$ MOV C,L$ MOV C,M$ MOV C,A$'  ;4C-4F
  1404.     dc.b    ' MOV D,B$ MOV D,C$ MOV D,D$ MOV D,E$'  ;50-53
  1405.     dc.b    ' MOV D,H$ MOV D,L$ MOV D,M$ MOV D,A$'  ;54-57
  1406.     dc.b    ' MOV E,B$ MOV E,C$ MOV E,D$ MOV E,E$'  ;58-5B
  1407.     dc.b    ' MOV E,H$ MOV E,L$ MOV E,M$ MOV E,A$'  ;5C-5F
  1408.     dc.b    ' MOV H,B$ MOV H,C$ MOV H,D$ MOV H,E$'  ;60-63
  1409.     dc.b    ' MOV H,H$ MOV H,L$ MOV H,M$ MOV H,A$'  ;64-67
  1410.     dc.b    ' MOV L,B$ MOV L,C$ MOV L,D$ MOV L,E$'  ;68-6B
  1411.     dc.b    ' MOV L,H$ MOV L,L$ MOV L,M$ MOV L,A$'  ;6C-6F
  1412.     dc.b    ' MOV M,B$ MOV M,C$ MOV M,D$ MOV M,E$'  ;70-73
  1413.     dc.b    ' MOV M,H$ MOV M,L$ HLT$     MOV M,A$'  ;74-77
  1414.     dc.b    ' MOV A,B$ MOV A,C$ MOV A,D$ MOV A,E$'  ;78-7B
  1415.     dc.b    ' MOV A,H$ MOV A,L$ MOV A,M$ MOV A,A$'  ;7C-7F
  1416.     dc.b    ' ADD B$   ADD C$   ADD D$   ADD E$  '  ;80-83
  1417.     dc.b    ' ADD H$   ADD L$   ADD M$   ADD A$  '  ;84-87
  1418.     dc.b    ' ADC B$   ADC C$   ADC D$   ADC E$  '  ;88-8B
  1419.     dc.b    ' ADC H$   ADC L$   ADC M$   ADC A$  '  ;8C-8F
  1420.     dc.b    ' SUB B$   SUB C$   SUB D$   SUB E$  '  ;90-93
  1421.     dc.b    ' SUB H$   SUB L$   SUB M$   SUB A$  '  ;94-97
  1422.     dc.b    ' SBB B$   SBB C$   SBB D$   SBB E$  '  ;98-9B
  1423.     dc.b    ' SBB H$   SBB L$   SBB M$   SBB A$  '  ;9C-9F
  1424.     dc.b    ' ANA B$   ANA C$   ANA D$   ANA E$  '  ;A0-A3
  1425.     dc.b    ' ANA H$   ANA L$   ANA M$   ANA A$  '  ;A4-A7
  1426.     dc.b    ' XRA B$   XRA C$   XRA D$   XRA E$  '  ;A8-AB
  1427.     dc.b    ' XRA H$   XRA L$   XRA M$   XRA A$  '  ;AC-AF
  1428.     dc.b    ' ORA B$   ORA C$   ORA D$   ORA E$  '  ;B0-B3
  1429.     dc.b    ' ORA H$   ORA L$   ORA M$   ORA A$  '  ;B4-B7
  1430.     dc.b    ' CMP B$   CMP C$   CMP D$   CMP E$  '  ;B8-BB
  1431.     dc.b    ' CMP H$   CMP L$   CMP M$   CMP A$  '  ;BC-BF
  1432.     dc.b    ' RNZ$     POP B$  AJNZ $   AJMP $   '  ;C0-C3
  1433.     dc.b    'ACNZ $    PUSH B$ CADI $    RST 0$  '  ;C4-C7
  1434.     dc.b    ' RZ$      RET$    AJZ $     ILLEGAL$'  ;C8-CB
  1435.     dc.b    'ACZ $    ACALL $  CACI $    RST 1$  '  ;CC-CF
  1436.     dc.b    ' RNC$     POP D$  AJNC $   COUT $   '  ;D0-D3
  1437.     dc.b    'ACNC $    PUSH D$ CSUI $    RST 2$  '  ;D4-D7
  1438.     dc.b    ' RC$      ILLEGAL$AJC $    CIN $    '  ;D8-DB
  1439.     dc.b    'ACC $     ILLEGAL$CSBI $    RST 3$  '  ;DC-DF
  1440.     dc.b    ' RPO$     POP H$  AJPO $    XTHL$   '  ;E0-E3
  1441.     dc.b    'ACPO $    PUSH H$ CANI $    RST 4$  '  ;E4-E7
  1442.     dc.b    ' RPE$     PCHL$   AJPE $    XCHG$   '  ;E8-EB
  1443.     dc.b    'ACPE $    ILLEGAL$CXRI $    RST 5$  '  ;EC-EF
  1444.     dc.b    ' RP$      POP PSW$AJP $     DI$     '  ;F0-F3
  1445.     dc.b    'ACP $     PUSH P$ CORI $    RST 6$  '  ;F4-F7
  1446.     dc.b    ' RM$      SPHL$   AJM $     EI$     '  ;F8-FB
  1447.     dc.b    'ACM $     ILLEGAL$CCPI $    RST 7$  '  ;FC-FF
  1448.     page
  1449. *************************************************************************
  1450. *                                    *
  1451. *    Fake FDOS                            *
  1452. *                                    *
  1453. *************************************************************************
  1454.  
  1455. *
  1456. * Fake BDOS for    target system
  1457. *
  1458. fdos    dc.b    $76,0,$C9    ;BIOS jump table
  1459.     dc.b    $C3,$33,$FF    ;Warm boot
  1460.     dc.b    $C3,$36,$FF    ;Console status
  1461.     dc.b    $C3,$39,$FF    ;Console input
  1462.     dc.b    $C3,$3C,$FF    ;Console output
  1463.     dc.b    $C3,$3F,$FF    ;List output
  1464.     dc.b    $C3,$42,$FF    ;Punch output
  1465.     dc.b    $C3,$45,$FF    ;Reader    input
  1466.     dc.b    $C3,$48,$FF    ;Home disk
  1467.     dc.b    $C3,$4B,$FF    ;Select    disk
  1468.     dc.b    $C3,$4E,$FF    ;Set track
  1469.     dc.b    $C3,$51,$FF    ;Set sector
  1470.     dc.b    $C3,$54,$FF    ;Set DMA address
  1471.     dc.b    $C3,$57,$FF    ;Read
  1472.     dc.b    $C3,$5A,$FF    ;Write
  1473.     dc.b    $C3,$5D,$FF    ;Get list device status
  1474.     dc.b    $C3,$60,$FF    ;Sector    translation
  1475.  
  1476. *
  1477. * Fake BIOS for    target system
  1478. *
  1479.     dc.b    $76,1,$C9    ;Warm boot
  1480.     dc.b    $76,2,$C9    ;Console status
  1481.     dc.b    $76,3,$C9    ;Console input
  1482.     dc.b    $76,4,$C9    ;Console output
  1483.     dc.b    $76,5,$C9    ;List output
  1484.     dc.b    $76,6,$C9    ;Punch output
  1485.     dc.b    $76,7,$C9    ;Reader    input
  1486.     dc.b    $76,8,$C9    ;Home disk *
  1487.     dc.b    $76,9,$C9    ;Select    disk *
  1488.     dc.b    $76,10,$C9    ;Set track *
  1489.     dc.b    $76,11,$C9    ;Set sector *
  1490.     dc.b    $76,12,$C9    ;Set DMA address *
  1491.     dc.b    $76,13,$C9    ;Read *
  1492.     dc.b    $76,14,$C9    ;Write *
  1493.     dc.b    $76,15,$C9    ;Get list device status    *
  1494.     dc.b    $76,16,$C9    ;Sector    translation *
  1495.  
  1496. fdoslen    equ    *-fdos
  1497.  
  1498. *
  1499. * BDOS function    vector table
  1500. *
  1501.     cnop    0,4
  1502. bdostab    dc.l    bdos00,bdos01,bdos02,bdos03,bdos04,bdos05,bdos06,bdos07
  1503.     dc.l    bdos08,bdos09,bdos10,bdos11,bdos12,bdos13,bdos14,bdos15
  1504.     dc.l    bdos16,bdos17,bdos18,bdos19,bdos20,bdos21,bdos22,bdos23
  1505.     dc.l    bdos24,bdos25,bdos26,bdos27,bdos28,bdos29,bdos30,bdos31
  1506.     dc.l    bdos32,bdos33,bdos34,bdos35,bdos36
  1507. bdostabn:
  1508.  
  1509. *
  1510. * BIOS function vector table
  1511. *
  1512.     cnop    0,4
  1513. biostab    dc.l    bdosfn,bios01,bios02,bios03,bios04,bios05,bios06,bios07
  1514.     dc.l    bios08,bios09,bios10,bios11,bios12,bios13,bios14,bios15
  1515. biostabn:
  1516.     page
  1517. *************************************************************************
  1518. *                                    *
  1519. *    Messages                            *
  1520. *                                    *
  1521. *************************************************************************
  1522.  
  1523. dosname    dc.b    'dos.library',0
  1524. aprompt    dc.b    'A>$'
  1525. crlfmsg    dc.b    cr,lf,'$'
  1526. spacemsg dc.b    ' $'
  1527. bsmsg    dc.b    bs,' ',bs,'$'    ;Erases the previous character
  1528. simsg    dc.b    si,'$'        ;Resets MSB of each output character
  1529. rawspec    dc.b    'RAW:0/0/640/200/CP/M Emulator'
  1530.     dc.b    ' by Jim Cathey and Charlie Gibbs - version '
  1531.     dc.b    vermaj&15+'0','.'
  1532.     dc.b    vermin/16+'0',vermin&15+'0',' ('
  1533.     dc.b    revyear/16+'0',revyear&15+'0','/'
  1534.     dc.b    revmonth/16+'0',revmonth&15+'0','/'
  1535.     dc.b    revday/16+'0',revday&15+'0',')',0
  1536. rawerr    dc.b    'Unable to open RAW: - code $'
  1537. setwin    dc.b    $9B,'0x',$9B,'8y',$9B,'24t',$9B,'80u',$9B,'H',$9B,'J$'
  1538. fullmsg    dc.b    'Too many files are open!',cr,lf,'$'
  1539. illgmsg    dc.b    cr,lf,'Illegal instruction $'
  1540. ilgmsg2    dc.b    ' at $'
  1541. ilgmsg3    dc.b    '.$'
  1542. dumpmsg    dc.b    cr,lf,'Register contents:$'
  1543. dmpmsg2    dc.b    cr,lf
  1544.     dc.b    '-AF- -BC- -DE- -HL- -SP- -S0- -S1- -S2- -S3- -PC- -op-'
  1545.     dc.b    cr,lf,'$'
  1546. dmpmsg3    dc.b    'Q to quit program, G to go on without tracing,'
  1547.     dc.b    'any other key to continue: $'
  1548. ilgbios    dc.b    cr,lf,'Illegal BIOS call $'
  1549. ilgbdos    dc.b    cr,lf,'Illegal BDOS call $'
  1550. tracemsg dc.b    cr,lf,'Start trace at >$'
  1551. tracemg2 dc.b    '  End trace at >$'
  1552. btrcmsg    dc.b    'Trace BIOS/BDOS calls? >$'
  1553. biosmsg    dc.b    'BIOS call $'
  1554. bdosmsg    dc.b    'BDOS call $'
  1555. atmsg    dc.b    ' at $'
  1556. esctran    dc.b    'ABCD',ff,so,si,'H',$8D,'JKLMP'    ;Escape sequence translation
  1557. prtname    dc.b    'PRT:RAW',0
  1558. badprt    dc.b    'Unable to open the list device!$'
  1559.     page
  1560. *************************************************************************
  1561. *                                    *
  1562. *    Variable storage                        *
  1563. *                                    *
  1564. *************************************************************************
  1565.  
  1566.     bss    bss
  1567.  
  1568. savesp    ds.l    1        ;Stack pointer save area
  1569. dosbase    ds.l    1        ;Pointer to dos.library
  1570. stdin    ds.l    1        ;Keyboard handle (stdin)
  1571. stdout    ds.l    1        ;Screen    handle (stdout)
  1572. rawhand    ds.l    1        ;RAW: file handle
  1573. prthand    ds.l    1        ;PRT:RAW file handle
  1574. handles    ds.l    8        ;File handles for opened files (or zero)
  1575. handlen:            ;End of    file handle table
  1576. dmaaddr    ds.l    1        ;Current DMA address
  1577. comend    ds.l    1        ;End of .COM file name on command line
  1578. cmdline    ds.b    128        ;Command line
  1579. cmdlinen:            ;End of    command    line
  1580. comname    ds.b    13        ;Name of file to load
  1581. comnamen:            ;End of    file name
  1582. opnname    ds.b    17        ;File name for OPEN or RENAME
  1583. renname    ds.b    17        ;New file name for RENAME
  1584. newrega    ds.b    1        ;BIOS/BDOS accumulator work area
  1585. workbuf    ds.b    80        ;Work buffer for "pstring" (including $)
  1586. workbufn:            ;End of work buffer
  1587. strbuf    ds.b    2048        ;String output buffer
  1588. strbufn    ds.b    8        ;"strbuf" overflow area - must follow "strbuf"!
  1589. strptr    ds.l    1        ;Current position in "strbuf"
  1590. escbuf    ds.b    8        ;Translated escape sequence
  1591. esclen    ds.w    1        ;Number of bytes saved in "escbuf"
  1592. cmdflag    ds.b    1        ;Take program name from command line.
  1593. quitflg    ds.b    1        ;"quitprg" exit flag
  1594. testdol    ds.b    1        ;"pstring" should test for leading $
  1595. insflag    ds.b    1        ;We're in insert mode.
  1596. dumpcnt    ds.b    1        ;"dump" counter for pausing
  1597. btrcflg    ds.b    1        ;Trace BIOS/BDOS calls.
  1598. bufflag    ds.b    1        ;Console output is buffered.
  1599. fcbptr    ds.l    1        ;Pointer to current FCB
  1600. listopn    ds.b    1        ;The list device is open.
  1601. *************************************************************************
  1602. *                                    *
  1603. *    Target processor's address space                                *
  1604. *                                    *
  1605. *************************************************************************
  1606.  
  1607.     even
  1608.  
  1609. registers ds.b    10        ;Actual    storage    for 8080's other registers
  1610. target    ds.b    $10000        ;8080's universe
  1611.  
  1612.     end
  1613.